function $xyFountPop(){
	var self = this;
	this.el = {
		box: document.createElement("div"),
		bg: document.createElement("div"),
		main: document.createElement("div"),
		title: document.createElement("div"),
		content: document.createElement("div"),
		btn: document.createElement("div")
	};
	this.el.box.classList.add('xy-pop-box');
	this.el.bg.classList.add('xy-pop-bg');
	this.el.main.classList.add('xy-pop-main');
	this.el.title.classList.add('xy-pop-title');
	this.el.content.classList.add('xy-pop-content');
	this.el.btn.classList.add('xy-pop-btn');
	this.btn = function(btnNumber,arrTxt){
		var _num = btnNumber == 1 ? 1 : 2;
		var _txt = [];
		if(Array.isArray(arrTxt) && arrTxt.length > 0){
			_txt = arrTxt;
		}else if(_num == 1){
			_txt = arrTxt || ['确定'];
		}else{
			_txt = ['取消','确定'];
		}
		switch(_num){
			case 1:
				this.el.btn.innerHTML = '<a href="javascript:void(0)" id="xy-pop-confirm">'+(_txt[0] || '确定')+'</a>';
				break;
			case 2:
				this.el.btn.innerHTML = '<a href="javascript:void(0)" id="xy-pop-close">'+_txt[0]+'</a><a href="javascript:void(0)" id="xy-pop-confirm">'+_txt[1]+'</a>';
				break;
			default:
				break;
		}
	}
	this.dialog = function(title){
		document.body.appendChild(this.el.box);
		this.el.box.appendChild(this.el.bg);
		this.el.box.appendChild(this.el.main);
		this.el.main.appendChild(this.el.title);
		this.el.main.appendChild(this.el.content);
		this.el.main.appendChild(this.el.btn);
	}
	this.close = function(time,bol){
		var _time = time || 0;
		if(bol){
			_time = typeof time == "number" && time > 20 ? time : typeof time == "number" && time < 20 ? time*1000 : 2000;
		}
		setTimeout(function(){
			self.el.box.remove();
		},_time);
	}
	this.tip = function(msg,btnStyle,callback){
		var tip = {};
		tip.msg = msg || "信息为null"
		if(typeof btnStyle == 'function'){
			tip.callback = btnStyle;
		}else{
			tip.btnStyle = btnStyle || '',
			tip.callback  = typeof callback == "function" ? callback : function(){}
		}
		this.el.title.style.display = 'none';
		this.el.content.innerHTML = tip.msg;
		this.btn(1);
		this.dialog();
		document.querySelector("#xy-pop-confirm").style.cssText += typeof tip.btnStyle == "function" ? "" : tip.btnStyle;;
		document.querySelector("#xy-pop-confirm").onclick = function(){
			tip.callback();
			self.close();
		}
	};
	this.msg = function(msg,title,callback){
		var tip = '';
		if(typeof arguments[0] == "object"){
			tip = arguments[0];
			if(!tip.btns || tip.btns == ""){
				tip.btns = ["取消","确定"];
			}
			if(!tip.title || tip.title == ""){
				tip.title = "信息提示！";
			}
			if(!tip.msg || tip.msg == ""){
				tip.msg = "还没有加入内容！";
			}
			if(!tip.btnStyle || tip.btnStyle == ""){
				tip.btnStyle = "";
			}
			if(!tip.callback || tip.callback == ""){
				tip.callback = function(){};
			}
			if(typeof arguments[1] == "function"){
				tip.callback = arguments[1];
			}
		}else{
			tip = {};
			tip.msg = msg || "还没有加入内容！";
			if(typeof title == "function"){
				tip.callback = title;
				tip.title = "信息提示！";
			}else{
				tip.title = title;
				tip.callback = callback;
			}
			tip.btns = ['取消','确定'];
		}
		this.el.content.innerHTML = tip.msg;
		this.el.title.innerHTML = tip.title;
		this.btn(2,tip.btns);
		this.dialog();
		if(Array.isArray(tip.btnStyle)){
			if(tip.btnStyle.length == 1){
				tip.btnStyle = ["",btnStyle[0]]
			}
			document.querySelector("#xy-pop-confirm").style.cssText += tip.btnStyle[1];
			document.querySelector("#xy-pop-close").style.cssText += tip.btnStyle[0];
		}
		document.querySelector("#xy-pop-confirm").onclick = function(){
			tip.callback({"index": 1});
			self.close();
		}
		document.querySelector("#xy-pop-close").onclick = function(){
			tip.callback({"index": 0});
			self.close();
		}
	};
	this.input = function(title,text,callback){
		var tip = '';
		if(typeof arguments[0] == "object"){
			tip = arguments[0];
			if(!tip.btns || tip.btns == ""){
				tip.btns = ["取消","确定"];
			}
			if(!tip.title || tip.title == ""){
				tip.title = "请输入内容！";
			}
			if(!tip.text || tip.text == ""){
				tip.text = "请输入内容！";
			}
			if(!tip.btnStyle || tip.btnStyle == ""){
				tip.btnStyle = "";
			}
			if(!tip.callback || tip.callback == ""){
				tip.callback = function(){};
			}
			if(typeof arguments[1] == "function"){
				tip.callback = arguments[1];
			}
		}else{
			tip = {};
			tip.title = title || "请输入内容！";
			if(typeof text == "function"){
				tip.text = "请输入内容！";
				tip.callback = text;
			}else{
				tip.text = text || "请输入内容！";
				tip.callback = typeof callback == "function" ? callback : function(){};
			}
			tip.btns = ['取消','确定'];
		}
		var html = '<input type="text" name="" id="xyPopInput" value="" placeholder="'+ tip.text +'"/>';
		this.el.title.innerHTML = tip.title;
		this.el.content.innerHTML = html;
		this.btn(2,tip.btns);
		this.dialog();
		if(Array.isArray(tip.btnStyle)){
			if(tip.btnStyle.length == 1){
				btnStyle = ["",btnStyle[0]]
			}
			document.querySelector("#xy-pop-confirm").style.cssText += tip.btnStyle[1];
			document.querySelector("#xy-pop-close").style.cssText += tip.btnStyle[0];
		}
		document.querySelector("#xy-pop-confirm").onclick = function(){
			tip.callback({"index": 1,"value": document.querySelector("#xyPopInput").value});
			self.close();
		}
		document.querySelector("#xy-pop-close").onclick = function(){
			tip.callback({"index": 0,"value": document.querySelector("#xyPopInput").value});
			self.close();
		}
	};
	this.show = function(msg,time,type){
		if(!msg){
			return;
		}
		var _type = typeof time != "number" ? time || "" : type || "";
		self.el.bg.style.cssText += "display: none;";
		self.el.main.classList.add("xy-pop-show");
		self.el.content.innerHTML = msg || "信息为null";
		self.dialog();
		self.close(time,true);
		switch(_type){
			case "top":
				self.el.main.style.cssText += 'top: 80px';break;
			case "bottom":
				self.el.main.style.cssText += 'top: auto;bottom: 80px;';
			default:
				break;
		}
	};
	this.toast = function(){
		document.body.appendChild(this.el.box);
		this.el.box.appendChild(this.el.bg);
		this.el.box.appendChild(this.el.main);
		this.el.main.classList.add("xy-pop-toast");
		this.el.bg.style.cssText += 'background: none';
	};
	this.loading = function(txt){
		var html = '<div class="xy-pop-load"><div></div></div><p>'+( txt ||'加载中...')+'</p>';
		this.el.main.innerHTML = html;
		this.toast();
	};
	this.fail = function(txt,time){
		var html = '<div class="xy-pop-fail"></div><p>'+(txt || '加载失败')+'</p>';
		this.el.main.innerHTML = html;
		this.toast();
		this.close(time,true);
	};
	this.ok = function(txt,time){
		var html = '<div class="xy-pop-fail"></div><p>'+(txt || '加载失败')+'</p>';
		this.el.main.innerHTML = html;
		this.toast();
		this.close(time,true);
	};
	this.icon = function(icon,txt,time){
		this.el.main.innerHTML = '<div>'+(icon || "")+'</div><p>'+(txt || '已收藏')+'</p>';
		this.toast();
		this.close(time,true);
	};
	this.topLoad = function(btns){
		this.toast(); 
	};
};
define(function(){
	return new $xyFountPop();
});
